<?php
//
//	file: calendar.php
//	author: ptirhiik
//	begin: 03/08/2003
//	version: 1.6.1 - 09/02/2007
//	license: http://opensource.org/licenses/gpl-license.php GNU General Public License (GPL)
//

define('IN_PHPBB', true);
define('IN_CALENDAR', true);

$phpbb_root_path = './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
$requester = 'calendar';
include($phpbb_root_path . 'common.' . $phpEx);

include($config->url('includes/calendar/class_calendar_handler'));
include($config->url('includes/calendar/class_calendar_page'));

//
// Start session management
//
$userdata = session_pagestart($user_ip, PAGE_INDEX);
$user->set($requester, array('calendar', 'viewtopic', 'viewprofile', 'class_forums', 'class_topics', 'class_posts', 'class_fields'));
//
// End session management
//

// choose layer
$_req = '';
if ( isset($HTTP_POST_VARS['y']) )
{
	$_req = &$HTTP_POST_VARS;
}
else
{
	$_req = &$HTTP_GET_VARS;
}
$day = isset($_req['d']) && intval($_req['d']) && isset($_req['m']) && intval($_req['m']);

// proceed with the appropriate layer
$calendar = $calendar_class = $tpl_body = false;
$page_title = $user->lang('Calendar');
$parms = array();
if ( $day )
{
	$calendar_class = 'calendar_day';
	$page_title = $user->lang('Calendar_scheduler');
	$tpl_body = 'calendar_scheduler_body.tpl';
}
else
{
	$calendar_class = 'calendar_month';
	$tpl_body = 'calendar_body.tpl';
}

// process the display
if ( $calendar_class )
{
	$calendar = new $calendar_class($requester);
	$calendar->display();
	$parms = $calendar->parms;
	$template->set_filenames(array('body' => $tpl_body));
}

// navigation
$navigation = new navigation();
$navigation->add('Calendar', '', $requester, array_merge($parms, array('h' => 0, 'i' => 0, 's' => 0, 'd' => 0)));
if ( isset($parms['d']) && $parms['d'] )
{
	$navigation->add('Calendar_scheduler', '', $requester, $parms);
}
$navigation->display();

// nothing to do, send message
if ( !$calendar_class )
{
	message_die(GENERAL_ERROR, 'Not_Authorised');
}
$calendar->destroy();
unset($calendar);

include($config->url('includes/page_header'));
$template->pparse('body');
include($config->url('includes/page_tail'));

?>